find_package(Qt${QT_MAJOR_VERSION}Concurrent ${QT_MIN_VERSION} QUIET)
find_package(KF${KF_MAJOR_VERSION}GuiAddons ${KF5_DEP_VERSION} QUIET)

set_package_properties(KF${KF_MAJOR_VERSION}GuiAddons PROPERTIES PURPOSE "Required to build the project addon")

# In KF5 KMoreTools is part of KNewSuff
# in KF6 it's standalone
if(KF_MAJOR_VERSION STREQUAL "5")
    find_package(KF5NewStuff QUIET)
    set_package_properties(KF5NewStuff PROPERTIES PURPOSE "Required to build the project addon")
else()
    find_package(KF6MoreTools QUIET)
    set_package_properties(KF6MoreTools PROPERTIES PURPOSE "Required to build the project addon")
endif()

if(NOT KF${KF_MAJOR_VERSION}_FOUND OR NOT Qt${QT_MAJOR_VERSION}Concurrent_FOUND)
  return()
endif()

if(NOT KF5NewStuff_FOUND AND NOT KF6MoreTools_FOUND)
  return()
endif()

kate_add_plugin(kateprojectplugin)
target_compile_definitions(kateprojectplugin PRIVATE TRANSLATION_DOMAIN="kateproject")

target_link_libraries(
    kateprojectplugin
    PRIVATE
        kateprivate
        Qt::Concurrent
        KF${KF_MAJOR_VERSION}::GuiAddons
        KF${KF_MAJOR_VERSION}::I18n
        KF${KF_MAJOR_VERSION}::TextEditor
)

if(KF_MAJOR_VERSION STREQUAL "5")
    target_link_libraries(kateprojectplugin PRIVATE KF5::NewStuff)
else()
    target_link_libraries(kateprojectplugin PRIVATE KF6::MoreTools)
endif()

target_sources(
  kateprojectplugin
  PRIVATE
    fileutil.cpp
    kateprojectplugin.cpp
    kateprojectpluginview.cpp
    kateproject.cpp
    kateprojectworker.cpp
    kateprojectitem.cpp
    kateprojectview.cpp
    kateprojectviewtree.cpp
    kateprojecttreeviewcontextmenu.cpp
    kateprojectinfoview.cpp
    kateprojectcompletion.cpp
    kateprojectindex.cpp
    kateprojectinfoviewindex.cpp
    kateprojectinfoviewterminal.cpp
    kateprojectinfoviewcodeanalysis.cpp
    kateprojectinfoviewnotes.cpp
    kateprojectconfigpage.cpp
    kateprojectcodeanalysistool.cpp
    branchesdialog.cpp
    branchcheckoutdialog.cpp
    branchesdialogmodel.cpp
    gitwidget.cpp
    gitstatusmodel.cpp
    gitcommitdialog.cpp
    stashdialog.cpp
    pushpulldialog.cpp
    comparebranchesview.cpp
    branchdeletedialog.cpp
    currentgitbranchbutton.cpp

    tools/clazy.cpp
    tools/clazycurrent.cpp
    tools/codeanalysisselector.cpp
    tools/cppcheck.cpp
    tools/flake8.cpp
    tools/shellcheck.cpp
    tools/eslint.cpp
    tools/clippy.cpp

    git/gitutils.cpp
    git/gitstatus.cpp

    plugin.qrc
)

install(FILES kateproject.example DESTINATION ${KDE_INSTALL_DATADIR}/kateproject)

if (BUILD_PCH)
    target_precompile_headers(kateprojectplugin REUSE_FROM katepch)
endif()

if(BUILD_TESTING)
  add_subdirectory(autotests)
endif()
